import { FormSchema } from '@/components/Form';

import { getAreaTree } from '@/api/common/index';

export const destinationFormSchemas: FormSchema[] = [
  {
    field: 'originArea',
    component: 'ApiCascader',
    label: '起运地城市',
    colProps: {
      span: 12,
      offset: 2,
    },
    componentProps: ({ formModel }) => {
      return {
        showSearch: true,
        placeholder: '请选择',
        api: getAreaTree,
        labelField: 'areaName',
        valueField: 'areaCode',
        displayRenderArray: formModel.originArea,
        onChange: (e, s, g, q) => {
          console.log(e, s, g, q);
          formModel.originCode = e[e.length - 1];
          formModel.originArea = [];
          // 判断省
          if (s) {
            formModel.originProvince = s.label;
            formModel.originArea[0] = s.label;
          } else {
            formModel.originProvince = '';
            formModel.originArea = e;
          }
          // 判断市

          if (g) {
            formModel.originCity = g.label;
            formModel.originArea[1] = g.label;
          } else {
            formModel.originCity = '';
            formModel.originArea = e;
          }

          // 判断区
          if (q) {
            formModel.originCounty = q.label;
            formModel.originArea[2] = q.label;
          } else {
            formModel.originCounty = '';
            formModel.originArea = e;
          }
        },
      };
    },
    required: true,
  },

  {
    field: 'originProvince',
    component: 'Input',
    show: false,
    label: '起点省',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'originCity',
    component: 'Input',
    show: false,
    label: '起点市',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'originCounty',
    component: 'Input',
    show: false,
    label: '起点区',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: false,
  },
  {
    field: 'originCode',
    component: 'Input',
    show: false,
    label: '起点编码',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },

  {
    field: 'destArea',
    component: 'ApiCascader',
    label: '目的地城市',
    colProps: {
      span: 12,
      offset: 2,
    },
    componentProps: ({ formModel }) => {
      return {
        showSearch: true,
        placeholder: '请选择',
        api: getAreaTree,
        labelField: 'areaName',
        valueField: 'areaCode',
        displayRenderArray: formModel.destArea,
        onChange: (e, s, g, q) => {
          console.log(e, s, g, q);
          formModel.destCode = e[e.length - 1];
          formModel.destArea = [];
          // 判断省
          if (s) {
            formModel.destProvince = s.label;
            formModel.destArea[0] = s.label;
          } else {
            formModel.destProvince = '';
            formModel.destArea = e;
          }
          // 判断市

          if (g) {
            formModel.destCity = g.label;
            formModel.destArea[1] = g.label;
          } else {
            formModel.destCity = '';
            formModel.destArea = e;
          }

          // 判断区
          if (q) {
            formModel.destCounty = q.label;
            formModel.destArea[2] = q.label;
          } else {
            formModel.destCounty = '';
            formModel.destArea = e;
          }
        },
      };
    },
    required: true,
  },
  {
    field: 'destProvince',
    component: 'Input',
    show: false,
    label: '终点省',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'destCity',
    component: 'Input',
    show: false,
    label: '终点市',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'destCounty',
    component: 'Input',
    show: false,
    label: '终点区',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: false,
  },
  {
    field: 'destCode',
    component: 'Input',
    show: false,
    label: '终点区编码',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
];

export const addContractSchema: FormSchema[] = [
  {
    field: 'contractCode',
    component: 'Input',
    label: '合同编号',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'contractTime',
    component: 'DatePicker',
    label: '签订日期',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    field: 'contractStartEndTime',
    component: 'RangePicker',
    label: '合作期限',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
      placeholder: ['开始日期', '结束日期'],
    },
  },
  // {
  //   field: 'contract_template',
  //   component: 'ImageUpload',
  //   label: '合同文件',
  //   colProps: {
  //     span: 16,
  //     offset: 2,
  //   },
  //   defaultValue: [
  //     // 'http://minio.es-jia.net/eslogispub/shippingOrder/5250bb8d5516a938505c298b5e6630b0.jpg',
  //   ],
  //   required: false,
  //   componentProps: {
  //     uploadParams: {
  //       configCode: 'eslogis_order',
  //       maxNumber: 10,
  //       label: 'contract_template',
  //       batchId: imgUuid,
  //     },
  //   },
  // },
];
